<?php
session_start();
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/ArticleService.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Entity/Domain/OrderDetailsDomain.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Entity/Info/OrderDetail.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Context/BaseContext.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/ServiceResult/ServiceResult.php';
if(isset($_GET['comm']))
{
		$vat = 0;
		if(isset($_SESSION['VAT']))
			$vat = $_SESSION['VAT'];
			
		$commTax = $_GET['comm'];
		
		$_SESSION['comm'] = $commTax;
		
		$res = array();
		$str = '';
		$totalAmount = 0;
		$totalBartTax = 0;
		$totalAmountAfterTaxFact = 0;		
		$strCurrency = "";
		$count = 1;
		$totalAmountFact = 0;
		if(isset($_SESSION['orderDetail']))
		{
			$orderDetailArr = $_SESSION['orderDetail'];
			foreach ($orderDetailArr as $orderDetail)
		    {
		    	$orderDetail = unserialize($orderDetail);
		    	$strCurrency = $orderDetail->getOrderdetailsDomain()->getCurrency();
		    	
		    	$totalAmount = $totalAmount + $orderDetail->getOrderdetailsDomain()->getAmount();
		    	$totalAmountFact = $totalAmountFact + $orderDetail->getOrderdetailsDomain()->getAmountFact();
		    	$count++;
		    }
		}
		$totalBartTax = $totalAmount * ($commTax/100);
		$totalAmountBeforeTax = $totalAmount + $totalBartTax;
		$totalAmountAfterTax = $totalAmountBeforeTax + ($totalAmountBeforeTax * ($vat/100));
	    $totalAmountAfterTaxFact = $totalAmountFact + ($totalAmountFact * ($vat/100));
	    $strTfoot = '
						<tr class="gradeX odd" style="height: 100px; border-top: 2px dotted #333 ;">
							<td colspan="9" style="vertical-align: middle;">comm commission B-Art '.$commTax.'%</td>                                 
							<td align="right" style="vertical-align: middle;">
	                                    	'.($commTax/100).'
							</td>
							<td align="right" style="vertical-align: middle;">
								'.$totalAmount.'
							</td>
	                                    <td align="center" style="vertical-align: middle;">
		                                    '.
	    										$strCurrency
		                                    .'
	                                    </td>
	                                    <td align="right" style="vertical-align: middle;">
											'.$totalBartTax.'
	                                    </td>
	                                    <td></td>
	                                </tr> 
	                                <tr class="gradeX odd1">
	                                	<td colspan="10">Amount Chargeable</td>
	                                	<td align="right">Total -</td>                            
	                                	<td align="center">
	                                		'.
	    										$strCurrency
		                                    .'
		                                </td>
	                                	<td class="total" align=right>
	                                		'.$totalAmountBeforeTax.'
	                                    </td>
	                                </tr>
	                                 <tr class="gradeX odd1">
	                                	<td colspan="9"></td>
	                                	<td>VAT</td>
	                                	<td style="text-align:right;">'.$vat.'%</td>                                	
	                                	<td>-</td>
	                                	<td align="right" style="border:1px solid #bbb ;">'.$totalAmountBeforeTax * ($vat/100).'</td>
	                                </tr>
	                                 <tr class="gradeX odd1">
	                                	<td colspan="10"></td>
	                                	<td align="right">Total</td>
	                                	<td align=center>	
	                                		'.
	    										$strCurrency
		                                    .'
	                                	</td>
	                                	<td align=right style="border:1px solid #bbb ;">
	                                		'.$totalAmountAfterTax.'
	                                    </td>
	                                </tr>
	                                <tr class="gradeX odd1">
                                	<td colspan="13" style="border-right:1px solid #bbb ;">Remarks:
                                		<p><textarea rows="6" cols="70" name="remarks">Please mention the invoice number when transferring money
B-Art Europe
Rabobank Gorinchem account 1043.51.721
IBAN NL95RABO0104351721 / BIC RABONL2U
BTW NR. NL138629857B01</textarea></p>
                                	</td>
                                	
	                                </tr>
	                                <tr class="gradeX odd1">
	                                	<td colspan="6" ></td>
	                                	<td colspan="7" style="border-right:1px solid #bbb ;">This is an automatically generated</td>
	                                </tr>                             
	                                <tr class="gradeX odd2">
	                                	<td colspan="6"></td>
	                                	<td colspan="3">document and therefore not signed</td>
	                                	<td colspan="4"  style="border-right:1px solid #bbb ;"></td>
	                                </tr>                  
	                                <input type="hidden" name="sum'.$strCurrency.'" value="'.$totalAmountAfterTax.'" >
	                                <input type="hidden" name="sum'.$strCurrency.'Fact" value="'.$totalAmountAfterTaxFact.'" > 
						';
		$res['tfoot'] = $strTfoot;
	    echo json_encode($res);	
}
?>